package models.chat.engines;

import play.jobs.Job;
import play.libs.F;

/**
 * @author Konovalov_Nik
 */

public class MessageEngine extends Job {
    public volatile boolean work = true;
    public static F.EventStream<QueueMessage> messageStream = new F.EventStream<QueueMessage>();

    @Override
    public void doJob() throws Exception {
        while (work) {
            QueueMessage queueMessage = messageStream.nextEvent().get();
            new MessageProcessor(queueMessage).now().get();
        }
    }

    public static void addMessage(QueueMessage message) {
        messageStream.publish(message);
    }
}
